package fun.coding.leetcode;

public class ConvertSortedArrayToBinarySearchTree {

	public static void main(String[] args) {
		/*
		 *     1, 2, 3, 4, 5, 6
		 *               3
		 *          1        5
		 *             2   4  6
		 * 
		 */
		
	}

    public TreeNode sortedArrayToBST(int[] num) {
    	if (num == null || num.length == 0) return null;
    	return helper(num, 0, num.length - 1);
    }
    
    public TreeNode helper(int[] num, int start, int end) {
    	if (start > end) return null;
    	
    	int mid = (end + start) / 2;
    	
    	TreeNode root = new TreeNode(num[mid]);
    	
    	root.left = helper(num, start, mid - 1);
    	root.right = helper(num, mid + 1, end);
    	
    	return root;
    }
}
